package com.sad.jetpack.v1.datamodel.api.extension.client.socket.ipc;


import java.net.Socket;

public abstract class AbsIPCChatRunnable implements IPCChatRunnable ,IPCChatSessionManager{

    private Socket socket;
    private IPCChatHeader header;
    private IPCMember selfMember;
    private IPCChatMessenger chatMessenger;
    protected IPCInternalExceptionListener exceptionListener;
    private IPCChatSession chatSession;
    public IPCChatSession getChatSession() {
        return chatSession;
    }

    public void setChatSession(IPCChatSession chatSession) {
        this.chatSession = chatSession;
    }
    protected void setExceptionListener(IPCInternalExceptionListener exceptionListener) {
        this.exceptionListener = exceptionListener;
    }

    private boolean isExit=false;

    protected boolean isExit() {
        return isExit;
    }

    protected void setSocket(Socket socket) {
        this.socket = socket;
    }

    public IPCChatMessenger getChatMessenger() {
        return chatMessenger;
    }

    protected void setChatMessenger(IPCChatMessenger chatMessenger) {
        this.chatMessenger = chatMessenger;
    }

    public Socket getSocket() {
        return socket;
    }

    protected void setHeader(IPCChatHeader header) {
        this.header = header;
    }

    protected void setSelfMember(IPCMember selfMember) {
        this.selfMember = selfMember;
    }

    public IPCMember getSelfMember() {
        return selfMember;
    }

    public IPCChatHeader getHeader() {
        return header;
    }

    public AbsIPCChatRunnable(){}

    @Override
    public void close() {
        end();
        try {
            socket.shutdownInput();
            socket.shutdownOutput();
            socket.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void end() {
        isExit=true;
    }

}
